/************************************************************************
This file is part of Polar4linux
Copyright (C) 2010-2011 Eric jrdn2
Portions Copyright (C) 2007 Matti Juvonen <mpj@iki.fi> (RS400 Tools)
Portions Copyright (C) 2006 Jani Hursti <jani.hursti@hut.fi>,
Portions Copyright (C) 2001-2003 Tom Oliveira e Silva

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
************************************************************************/

#ifndef _SESSIONVIEW_H
#define _SESSIONVIEW_H

#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <qevent.h>
#include <qdebug.h>
#include <math.h>
#include <iostream>
#include <QtAlgorithms>
#include <sys/stat.h>
#include <QDate>
#include <QMenu>
#include "polarSubs.h"

class pageView:public QGraphicsView
{
Q_OBJECT

public:
	pageView(QWidget *parent = 0);
	~pageView();
	void associate(polar4linuxInternals *internals0);
	void addGraph(graph* g);
	void clearPage(); //delete pointers and empty container
	void removeGraphs(); //juste empty container. pointers are deleted by someone else
	float computeRatio2Normal();
	void plotPage();
	void plotPreview(graph &g);
	void saveImage(QGraphicsScene *scene, QString filename);
	void setLayout(int h,int v);
	void computeBBox(graph *g, int posh,int posv,int nbthumbh,int nbthumbv, int totalh, int totalv);
	void computeBBoxPreview(graph *g, int posh,int posv,int nbthumbh,int nbthumbv, int totalh, int totalv);
	void highlightSelection();
	std::vector<graph*> graphs;
	graph* selectedGraph;
	signals:
	void pageIsEmpty();

	public slots:
		void clearSelectedGraph();

private:
	polar4linuxInternals *internals;
	QGraphicsScene *onlinescene;
	QGraphicsScene *previewscene;
	QPen gPen;
	QBrush gBrush;
	void resizeEvent ( QResizeEvent * event );
	void mousePressEvent(QMouseEvent *event);
	void mouseReleaseEvent(QMouseEvent *event);
	void mouseMoveEvent ( QMouseEvent * event );
	unsigned int gimmeGraphNum( QMouseEvent * event );
	
	int nbthumbh,nbthumbv;
	QGraphicsRectItem *selectionRect;
	unsigned int lastHoveredGraph;
	static const int extraMargin=2; //with this value, the scrolling bar does not appear (on this computer)
	static const int previewWidth=200;
	static const int previewHeight=150;
};

#endif
